package com.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Test10 {
    public static void main(String[] args) {

        String colors = "red,black,white,yellow,blue";

        // ========================
        // 把string类型的字符串切割开,获取其中每个元素的值
        // String[] split = colors.split(",");
        // List<String> stringList = Arrays.asList(split);
        //
        // if (stringList.size() > 0) {
        //     for (String s : stringList) {
        //         System.out.println(s);
        //     }
        // }

        // ========================
        // 连在一起的写法
        List<String> list = Arrays.asList(colors.split(","));
        if (list.size() > 0) {
            for (String s : list) {
                System.out.println(s);
            }

            String collect = list.stream().map(String::valueOf).collect(Collectors.joining(","));
            System.out.println("新的颜色为:" + collect);
        }

    }
}
